package com.rpc.client;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class RpcProxyClient {

    /**
     * 方向代理生成 service实现类对象
     * @param interfaceClazz
     * @param <T>
     * @return
     */
    public <T> T clientProxy(Class<T> interfaceClazz){

        return (T) Proxy.newProxyInstance(
                interfaceClazz.getClassLoader(),
                new Class<?>[]{interfaceClazz},
                new RemoteInvocationHandler( interfaceClazz.getName()));
    }

    public <T> T clientProxyLambda(Class<T> interfaceClazz){

        return (T) Proxy.newProxyInstance(
                    interfaceClazz.getClassLoader(),
                new Class<?>[]{interfaceClazz},
                (Object proxy, Method method, Object[] args)->{
                    System.out.println("lambda 表达式实现 InvocationHandler ");
                    return null;
                });
    }
}
